package com.mk.bstest.controller;


import com.mk.bstest.domain.Result;
import com.mk.bstest.domain.user;
import com.mk.bstest.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 28464
 */
@Controller
@RequestMapping("/user")
public class UserController {


    @Autowired
    IUserService userService;

    @GetMapping("index")
    public String toIndex(){
        return "index";
    }


    @GetMapping("main")
    public String toMain(){
        return "main";
    }

    @GetMapping("bs")
    public String toBs(){
        return "bs";
    }

    @GetMapping("list")
    @ResponseBody
    public List<user> listAll(){
        return userService.queryAll();
    }

    @PostMapping("delete")
    @ResponseBody
    public Result delete(Long id){
        userService.delete(id);
        return new Result("删除成功",true);
    }

    @PostMapping("insert")
    @ResponseBody
    public Result insert(user u){
        System.out.println("======="+u);
        userService.insert(u);
        return new Result("新增成功",true);
    }

    @PostMapping("update")
    @ResponseBody
    public Result update(user u){
        userService.update(u);
        return new Result("更新成功",true);
    }

}
